Skip to content

feat: allow removing property rules from validator by ids#171

Open
nieomylnieja wants to merge 6 commits into
mainfrom
allow-removing-property-rules-by-id
Open

feat: allow removing property rules from validator by ids#171
nieomylnieja wants to merge 6 commits into
mainfrom
allow-removing-property-rules-by-id

Conversation

@nieomylnieja

@nieomylnieja nieomylnieja commented Nov 12, 2025

Copy link
Copy Markdown
Collaborator

Motivation

Describe what is the motivation behind the proposed changes.
If possible reference the current solution/state of affairs.

Summary

Recap of changed code.

Related Changes

There's another PR which explores deleting properties by names: #172.

Testing

Each code change must be covered by unit tests.

Release Notes

If this change should be part of the Release Notes,
replace this entire paragraph with 1-3 sentences about the changes.
Otherwise, you MUST remove this section entirely.

Does this PR contain any breaking changes?
If so, add ## Breaking Changes header and list the introduced changes there.

- Updated `golangci-lint` from version 2.5.0 to 2.6.1 in `devbox.json` and `devbox.lock`.
- Introduced a new `uuid` package for generating UUIDs. The `GenerateUUID` function creates UUIDs compliant with version 4 specifications.
- Added comprehensive unit tests for the `uuid` package to ensure correctness, including format validation, uniqueness, length checks, and bit correctness.
- Enhanced the `govy` package with new features:
  - Added `instanceID` for unique identification of `Validator` and `PropertyRules` instances.
  - Introduced `WithID` and `GetID` methods for `Validator` and `PropertyRules` to manage and retrieve identifiers.
  - Implemented `RemoveProperties` in `Validator` to allow selective removal of properties or nested validators.
- Updated benchmarks in `rules` package to use `b.Loop()` for improved readability and consistency.
- Added new examples and tests to demonstrate and validate the usage of `RemoveProperties` and `GetID` functionalities.
@n9-machine-user n9-machine-user added enhancement New feature or request go Pull requests that update Go code minor New functionality with at most minor brekaing changes labels Nov 12, 2025
@github-actions

github-actions Bot commented Nov 12, 2025

Copy link
Copy Markdown

Test coverage changes:

Package Before After Diff
github.com/nobl9/govy/cmd/govy 0% 0% ✔️
github.com/nobl9/govy/internal 73% 73% ✔️
github.com/nobl9/govy/internal/collections 100% 100% ✔️
github.com/nobl9/govy/internal/inferpath 76% 76% ✔️
github.com/nobl9/govy/internal/messagetemplates 89% 89% ✔️
github.com/nobl9/govy/internal/stringconvert 86% 86% ✔️
github.com/nobl9/govy/internal/typeinfo 94% 94% ✔️
github.com/nobl9/govy/internal/uuid - 100% ✔️
github.com/nobl9/govy/pkg/govy 93% 94% ✔️
github.com/nobl9/govy/pkg/govytest 100% 100% ✔️
github.com/nobl9/govy/pkg/jsonpath 85% 85% ✔️
github.com/nobl9/govy/pkg/rules 98% 98% ✔️

This update introduces the ability to set custom identifiers for property rules using the `WithID` method. The feature is implemented across `PropertyRules`, `PropertyRulesForSlice`, and `PropertyRulesForMap`. These identifiers can be used for referencing specific rules, such as when removing properties from a validator.

The changes include:
- Implementation of the `WithID` method in `PropertyRules`, `PropertyRulesForSlice`, and `PropertyRulesForMap`.
- Updates to the `GetID` method to prioritize user-supplied IDs over names and auto-generated UUIDs.
- Modifications to example and test files to demonstrate and validate the new functionality.
- Adjustments to the `Makefile` to ignore `node_modules` during markdown linting.
This update introduces a shift from name-based property removal to ID-based property removal in the `govy` package. The changes include:

- Replacing `RemoveProperties` with `RemovePropertiesByID` in the `Validator` API.
- Modifying `PropertyRules.GetID` and `Validator.GetID` to return only user-supplied IDs or auto-generated UUIDs, removing reliance on property names.
- Updating examples and tests to reflect the new ID-based approach, ensuring clarity and consistency.
- Simplifying the internal logic for ID retrieval by consolidating methods in the `instanceID` struct.

These changes enhance the flexibility and reliability of property rule management, particularly in dynamic or complex validation scenarios.
@nieomylnieja nieomylnieja changed the title feat: allow removing property rules from validator feat: allow removing property rules from validator by ids Nov 13, 2025
nieomylnieja added a commit that referenced this pull request Nov 13, 2025
## Motivation

Sometimes you want to create a modified validator without certain rules,
the only way to achieve that currently is during the validator's
definition. If you are importing a module which defines a validator, you
have currently no way to change its rules in any way.

That's why it would be useful to be able to remove properties' rules by
name.

## Related Changes

There's another PR which explores deleting properties by IDs:
#171.

## Release Notes

Added `govy.Validator.RemovePropertiesByName` method.
…ty-rules-by-id

# Conflicts:
#	devbox.json
#	devbox.lock
#	pkg/govy/example_test.go
#	pkg/govy/rules.go
#	pkg/govy/rules_for_map.go
#	pkg/govy/rules_for_slice.go
#	pkg/govy/rules_test.go
#	pkg/govy/validation.go
#	pkg/govy/validator.go
Avoid mutating the enum value before bounds checking so unknown keys render
their original numeric value and valid lookups use a safe zero-based index.
Ensure `ForPointer` and `Transform` create generated property IDs so
`RemovePropertiesByID` can filter those rules consistently with `For`.
@nieomylnieja nieomylnieja marked this pull request as ready for review June 16, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update Go code minor New functionality with at most minor brekaing changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants